-- 情绪吸收
local race_qingxuxishou = fk.CreateSkill {
    name = "mcdh_race_qingxuxishou"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

race_qingxuxishou:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        if target ~= player and player:hasSkill(self) and target.phase == Player.Finish then
            local ids = {}
            local events =  player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
                for _, move in ipairs(e.data) do
                    if move.moveReason == fk.ReasonDiscard and move.from == target.id then
                        for _, info in ipairs(move.moveInfo) do
                            if player.room:getCardArea(info.cardId) == Card.DiscardPile then
                                table.insertIfNeed(ids, info.cardId)
                            end
                        end
                    end
                end
            end, Player.HistoryTurn)
            local suits = {}
            table.forEach(player:getPile("qingxuxishou_pile"),function(id) table.insertIfNeed(suits,Fk:getCardById(id).suit)  end)
            ids = table.filter(ids,function(id) return not table.contains(suits,Fk:getCardById(id).suit)  end)
            if #ids > 0 then
                self.cost_data = ids
                return true
            end
        end
    end,
    on_cost =function(self, event, target, player, data)
        local room = player.room
        local ids = self.cost_data
        local cards, _ = U.askforChooseCardsAndChoice(player, ids, {"OK"}, self.name,
                "#race-qingxuxishou-choose", {"Cancel"}, 1, 1)
        if #cards > 0 then
            self.cost_data = cards
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        player:addToPile("qingxuxishou_pile", self.cost_data, true, self.name, player.id)
    end
})

Fk:loadTranslationTable {
    ["mcdh_race_qingxuxishou"] = "情绪吸收",
    [":mcdh_race_qingxuxishou"] = "其他角色的结束阶段，你可以将该角色本回合弃置的一张牌（需与你武将牌上的花色均不同）置于你的武将牌上。",
    ["#race-qingxuxishou-choose"] = "情绪吸收: 将该角色一张牌置于你的武将牌上。",
    ["qingxuxishou_pile"] = "情绪吸收"
}

return race_qingxuxishou